/**
 * 返回大廳命令
 * 
 * @author LuoDong
 * @email luo4521@online.net.tw
 * 2010-2-7 20:06
 */
package com.addcn.texas.control {
	import com.addcn.fog.control.ICommand;
	import com.addcn.fog.control.SimpleCommand;
	
	import com.addcn.texas.Main;	
	import com.addcn.texas.model.*;
	import com.addcn.texas.view.*;	
	
	import com.addcn.common.utils.DestroyMemory;
		
	public class BackToHallCommand extends SimpleCommand implements ICommand {
		
		public override function execute(r_data:Object = null):void {	
			_addView();
			_addModel();			
			_handler();			
			_removeView();
			controller.addCommand(RemoveGameModelCommand);
			sendNotification(RemoveGameModelCommand);
			DestroyMemory.clear();			
		}
		
		/**
		 * 注冊view
		 */
		private function _addView() : void
		{
			viewLocator.addView(StartupView);  			
			viewLocator.addView(HallView); 							
			viewLocator.addView(FriendsView); 
			//發送通知，初始化大廳
			sendNotification(Main.APP_STARTUP); 
		}
		
		/**
		 * 注冊model
		 */
		private function _addModel() : void
		{
			modelLocator.addModel(HallModel);  
			modelLocator.addModel(UserInfoModel);			
		}
		
		private function _handler() : void
		{			
			var _model : Object;
			//站起
			//var _model : Object = modelLocator.getModel(RoomUserModel);
			//_model.standUp();
			
			//退出房間
			if(modelLocator.hasModel(RoomModel)){
				_model = modelLocator.getModel(RoomModel);
				_model.exitRoom();
			}				
			//獲取游戲場房間列表
			_model = modelLocator.getModel(RoomModel);
			var _type : int = _model.getType();
			_model = modelLocator.getModel(HallModel);
			_model.getRoomList( _type, true);
			
		}
		
		/**
		 * 移除view
		 */
		private function _removeView() : void
		{
			viewLocator.removeView(RoomView);
			viewLocator.removeView(RoomUserView);
			viewLocator.removeView(PokerView);
			//viewLocator.removeView(ChipsView);
			viewLocator.removeView(ChipView);
			viewLocator.removeView(GamePropsView);
		}
		
	
	}
}
